
{include file="common/_header"}
<body class="login-bg">
<style>
    .code-box{
        text-align: right;
        margin-top: 10px;
    }
</style>

<div class="login layui-anim layui-anim-up">
    <div class="message">美丽云后台管理忘记密码</div>
    <div id="darkbannerwrap"></div>


    <form method="post" class="layui-form" >
        <input name="type" type="hidden" value="3">
        <input name="user_name" placeholder="用户名" id="phone" type="text" lay-verify="required" class="layui-input" >
        <hr class="hr15">
        <input name="vcode" lay-verify="required" placeholder="验证码"  type="text" class="layui-input">
        <div class="code-box">
            <a class="send-code" onclick="sendvode()">发送验证码</a>
            <span class="read-second"></span>
        </div>
        <hr class="hr15">
        <input name="userpass" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
        <hr class="hr15">
        <input value="提交" id="login" lay-submit lay-filter="login" style="width:100%;" type="button">
        <hr class="hr20" >
    </form>
</div>
<script>

    function sendvode() {
        var phone = document.getElementById("phone").value;
        if(phone){
            $.ajax({
                url: '/Sendvcode',
                data: {phone: phone}, // 表单序列化
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    console.log(data);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 1500,
                        });
                    } else {
                        layer.open({
                            title: '发送失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6,
                        });
                    }
                }
            });
        }
    }

    function keyCodeShow(e)
    {
        var evt = e || window.event;
        console.log(evt.keyCode);
        if(evt.keyCode == 13){
            $('#login').click();
            return false;
        }
    }
    document.onkeydown=keyCodeShow;

    layui.use('form', function() {
        var form = layui.form;



        form.on('submit(login)', function (data) {
            $.ajax({
                url: '/admin/forgot',
                data: data.field, // 表单序列化
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    console.log(data);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 1500,
                        }, function () {
                            window.location.href = data.url;
                        });
                    } else {
                        layer.open({
                            title: '登录失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6,
                        });
                    }
                }
            });
        });
    });
    $('.send-code').on('click',function(e){
        e.preventDefault();
        $('.send-code').hide()
        let second = 60
        $('.read-second').show().text(`${second}秒`)
        const  timer =setInterval(()=>{
            second--;
            $('.read-second').text(`${second}秒`)
            if(second<=0){
                clearInterval(timer)
                $('.send-code').show()
                $('.read-second').hide()
            }
        },1000)
    })
</script>
</body>

{include file="common/_bottom"}